﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using System.Data.SqlClient;
using Jzy.Core.Utility;
using ECommerce.Model.Order;

namespace ECommerce.DAL.Order
{
    public class ECOrderDAL : BaseDAL
    {
        public long GetOrderID()
        {
            SqlParameter date = new SqlParameter();
            date.ParameterName = "@Date";
            date.SqlDbType = System.Data.SqlDbType.DateTime;
            date.Direction = System.Data.ParameterDirection.Output;

            SqlParameter number = new SqlParameter();
            number.ParameterName = "@Number";
            number.SqlDbType = System.Data.SqlDbType.Int;
            number.Direction = System.Data.ParameterDirection.Output;

            dbOper.RunProc("GenerateOrderID", date, number);
            
            string orderid = ((DateTime)date.Value).ToString("yyyyMMdd").Substring(2) + ((int)number.Value).ToString("000000");
            return long.Parse(orderid);
        }

        public void SetOrderState(List<string> ids, Model.Order.OrderState orderState)
        {
            string strIDs = ConvertUtil.ConvertToDbStr(ids);
            string sql = "update ECOrder set OrderState = " + (int)orderState + " where ID in (" + strIDs + ")";
            dbOper.RunSql(sql);
        }

        public List<ECOrderInfo> GetList(string ids)
        {
            string sql = "select * from ECOrder where ID in (" + ids.Trim(',') + ")";
            return dbOper.Query<ECOrderInfo>(sql);
        }
    }

}
